import 'package:flutter/material.dart';
import 'package:flutter_enjoy_plus/page/home/components/home_nav.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('享+社区'),
        centerTitle: true,
        backgroundColor: Colors.transparent,
      ),
      backgroundColor: const Color(0xffd2dde8),
      body: ListView(
        children: [
          HomeNav(),
          // 顶部横幅图片
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
            child: ClipRRect(
              borderRadius: BorderRadius.circular(12),
              child: Image.asset(
                'assets/images/banner@2x.jpg',
                fit: BoxFit.cover,
                height: 120,
                width: double.infinity,
              ),
            ),
          ),
          // 社区公告标题
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
            child: Row(
              children: [
                Image.asset(
                  'assets/images/notice@2x.png',
                  width: 20,
                  height: 20,
                ),
                const SizedBox(width: 6),
                const Text(
                  '社区',
                  style: TextStyle(
                      fontSize: 16,
                      color: Colors.black87,
                      fontWeight: FontWeight.bold),
                ),
                const SizedBox(width: 2),
                Text(
                  '公告',
                  style: TextStyle(
                      fontSize: 16,
                      color: Color(0xFFFFA800),
                      fontWeight: FontWeight.bold),
                ),
              ],
            ),
          ),
          // 公告卡片列表
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
            child: Column(
              children: List.generate(2, (index) => _buildNoticeCard()),
            ),
          ),
        ],
      ),
    );
  }
}

// 新增公告卡片构建方法
Widget _buildNoticeCard() {
  return Container(
    margin: const EdgeInsets.only(bottom: 12),
    padding: const EdgeInsets.all(16),
    decoration: BoxDecoration(
      color: Colors.white,
      borderRadius: BorderRadius.circular(12),
      boxShadow: [
        BoxShadow(
          color: Colors.black12,
          blurRadius: 4,
          offset: Offset(0, 2),
        ),
      ],
    ),
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        const Text(
          '药品喷洒通知',
          style: TextStyle(
              fontSize: 15, fontWeight: FontWeight.bold, color: Colors.black87),
        ),
        const SizedBox(height: 8),
        const Text(
          '社区定于8月3日中午喷洒灭蚊药，提醒大家看管好小孩及宠物，不要到草坪中玩耍，以免造成不必要的伤害。',
          style: TextStyle(fontSize: 13, color: Colors.black54),
        ),
        const SizedBox(height: 12),
        const Text(
          '2022-08-03 16:00',
          style: TextStyle(fontSize: 12, color: Colors.grey),
        ),
      ],
    ),
  );
}
